<template>
  <div class="yy-tab-content">
    <el-tabs >
      <el-tab-pane v-for="(item, index) in list" :key="index" :label="item.title">
        <el-scrollbar max-height="300px">
          <div class="content" v-for="(cont, ind) in item.content" :key="ind" @click="handleItem(cont, ind)">
            <div class="avatar" v-if="cont.avatar">
              <el-avatar size="small" :src="cont.avatar" />
            </div>
            <div class="info">
              <div v-if="cont.title" class="tit">
                <div>
                  {{cont.title}}
                </div>
                <div class="tag" v-if="cont.tag">
                  <el-tag :type="cont.tagType" size="small">{{cont.tag}}</el-tag>
                </div>
              </div>
              <div class="gray" v-if="cont.desc">{{cont.desc}}</div>
              <div class="gray" v-if="cont.time">{{cont.time}}</div>
            </div>
          </div>
        </el-scrollbar>
        <div class="actions">
          <div v-for="(act, index) in actions" :key="index" class="action-item" @click="handleActionItem(act, index)">
            <div class="icon" v-if="act.icon">
              <component :is="`el-icon-${toLine(act.icon)}`"></component>
            </div>
            <div class="text">{{act.text}}</div>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script setup lang="ts">
  import { List, ListItem, ActionItem} from './type'
  import { toLine } from '../../utils/index'

  defineOptions({
    name: 'NotificationList'
  })

  let props = defineProps({
    list: {
      type: Array as PropType<List[]>,
      require: true
    },
    actions: {
      type: Array as PropType<ActionItem[]>,
      default: () => []
    }
  })
  let emits = defineEmits(['handleClickItem', 'handleClickAction'])
  const handleItem = (item: ListItem, index: number) => {
    emits('handleClickItem', {item, index})
  }
  const handleActionItem = (item: ActionItem, index: number) => {
    emits('handleClickAction', {item, index})
  }
</script>

<style scoped lang="scss">
.content{
  display: flex;
  align-items: center;
  padding: 12px 0;
  &:hover{
    background: #67E0FC;
  }
  .avatar{
    flex: 1;
    text-align: center;
  }
  .info{
    flex: 3;
    .tit{
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
  }
  .gray{
    color: #999;
    font-size: 14px;
    margin-top: 4px;
  }
}
.actions{
  display: flex;
  align-items: center;
  border-top: 1px solid #eeeeee;
  .action-item{
    height: 50px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    &+.action-item{
      border-left: 1px solid #eeeeee;
    }
    .icon{
      margin-right: 4px;
      position: relative;
      top: 2px;
    }
  }
}
</style>
